package com.example.dubbo.demo.provider.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.example.dubbo.demo.api.domain.UserAddress;

import com.example.dubbo.demo.api.service.UserService;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

//这个Service是dubbo的注解，表示将该服务暴露出去
@Service
//为了避免注解一样，将这里改成Component
@Component
public class UserServiceImpl implements UserService {

    //@HystrixCommand
    @Override
    public List<UserAddress> getUserAddressList(String userId) {
        //这里为了简便，不连数据库了
        UserAddress address1 = new UserAddress(1, "河南省郑州巩义市宋陵大厦2F", "1", "安然", "150360313x", "Y");
        UserAddress address2 = new UserAddress(2, "北京市昌平区沙河镇沙阳路", "1", "情话", "1766666395x", "N");


        // 随机会报错
        if(Math.random() > 0.5){
            throw new RuntimeException();
        }

        return Arrays.asList(address1,address2);
    }
}
